Skip to content

Switch to use romanisim#100

Open
yuedong0607 wants to merge 11 commits into
mainfrom
switch_to_use_romanisim
Open

Switch to use romanisim#100
yuedong0607 wants to merge 11 commits into
mainfrom
switch_to_use_romanisim

Conversation

@yuedong0607

@yuedong0607 yuedong0607 commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

This RP migrates the codebase to a new set of APIs in romanisim (here's an introduction of the new API), replacing all usages of galsim.roman. This change enables access to both CRDS and the roman-technical-information repository.

Current status:

  • Replaced all galsim.roman calls with romanisim APIs.
  • Updated the bandpass class to support spatially varying (per-SCA) throughputs, calculated from effective area files retrieved from roman-technical repo.
  • Added configurable options for individual instrumental effects in noise.py

TODO / Open Questions (for this PR):

  • Configuration schema: Finalize the format of configurable options in the YAML config. Some modules can take additional parameters for further configuration (see an example below for the nonlinearity module)

TODO / Open Questions (out of scope for this PR):

  • WCS: Currently still using the same implementation inherited from galsim.roman. Need to consider switching to use the romanisim.wcs APIs which is based on gwcs and leverages the CRDS distortion models.
  • PSF: Currently still using the same implementation inherited from galsim.roman. Need to consider switching to use the romanisim.psf APIs which supports both empirical PSF samples from CRDS, and STPSF models. However, both the empirical PSF and STPSF in romanisim.psf only support achromatic modeling at this moment.
from romanisim.models import Nonlinearity
nl = Nonlinearity(
        usecrds=True,
        reftype="inverselinearity",
        getdq=True,
        integralnonlinearity=None,
        metadata=None,
        image_mod=None,
        reffiles=None,
        saturation=None,
        Coeffs=None,
        gain=None,
)
nl.apply(img, electrons=False)
integralnonlinearity : object or None, optional
        Optional integral nonlinearity reference model. If provided, the class
        constructs channel-based lookup corrections that are added after the
        polynomial correction.

@yuedong0607 yuedong0607 force-pushed the switch_to_use_romanisim branch 2 times, most recently from 93c4cf2 to ac91f55 Compare April 30, 2026 21:46
@yuedong0607

Copy link
Copy Markdown
Collaborator Author

romanisim.models has not yet been included in the current release (v0.13.1) of romanisim. The merge needs to wait until the next release version.

@yuedong0607

Copy link
Copy Markdown
Collaborator Author

I updated the romanisim dependency in pyproject.toml to point to the main branch, and all unit tests are now passing. I think the code is ready for review now. @arunkannawadi

@yuedong0607 yuedong0607 force-pushed the switch_to_use_romanisim branch from 88819ea to 414da08 Compare May 28, 2026 20:39

@arunkannawadi arunkannawadi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed everything expect for the changes in psf.py. Given the slowness you report, I think that needs some investigation.

Comment thread roman_imsim/bandpass.py Outdated
Comment thread roman_imsim/config/hack.yaml Outdated
Comment thread roman_imsim/noise.py Outdated
Comment thread roman_imsim/noise.py Outdated
@yuedong0607

Copy link
Copy Markdown
Collaborator Author

I have reviewed everything expect for the changes in psf.py. Given the slowness you report, I think that needs some investigation.

It seems like the efficiency issue appears in both this branch and the integrated_coadd_sim branch (which doesn't use romanisim.models yet). I'm running some tests now.

@yuedong0607 yuedong0607 force-pushed the switch_to_use_romanisim branch from 8ebb3be to 97ea3b9 Compare June 16, 2026 06:24
@yuedong0607

Copy link
Copy Markdown
Collaborator Author

I have reviewed everything expect for the changes in psf.py. Given the slowness you report, I think that needs some investigation.

I ran a round of code profiling last week and found that the performance issues previously observed in this branch were likely caused by some temporary problems on the DCC side. I've rebased the branch. It should now be ready for merging or any further review.

Comment thread roman_imsim/psf.py
Comment on lines +80 to +117
def __init__(
self,
SCA=None,
WCS=None,
n_waves=None,
bpass=None,
extra_aberrations=None,
logger=None,
):

logger = galsim.config.LoggerWrapper(logger)

if n_waves == -1:
if bpass.name == "W146":
n_waves = 10
else:
n_waves = 5

corners = [
galsim.PositionD(1, 1),
galsim.PositionD(1, models.parameters.n_pix),
galsim.PositionD(models.parameters.n_pix, 1),
galsim.PositionD(models.parameters.n_pix, models.parameters.n_pix),
]
cc = galsim.PositionD(models.parameters.n_pix / 2, models.parameters.n_pix / 2)
tags = ["ll", "lu", "ul", "uu"]
self.PSF = {}
pupil_bin = 8
self.PSF[pupil_bin] = {}
for tag, SCA_pos in tuple(zip(tags, corners)):
self.PSF[pupil_bin][tag] = self._psf_call(
SCA, bpass, SCA_pos, WCS, pupil_bin, n_waves, logger, extra_aberrations
)
for pupil_bin in [4, 2, "achromatic"]:
self.PSF[pupil_bin] = self._psf_call(
SCA, bpass, cc, WCS, pupil_bin, n_waves, logger, extra_aberrations
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added back here?
The PSFInterpolator is not supposed to be changed. It is only use as a constructor for specific interpolation scheme. What is being added here is already in the initPSF of the CornerPSFInterpolator see here.
Also this modification has nothing to do with this PR, is there is an issue/bug with the PSF implementation please make a separate PR to make it easier to track.

Comment thread roman_imsim/stamp.py
Comment on lines +124 to +146
def buildPSF(self, config, base, gsparams, logger):
"""Build the PSF object.

For the Basic stamp type, this builds a PSF from the base['psf'] dict, if present,
else returns None.

Parameters:
config: The configuration dict for the stamp field.
base: The base configuration dict.
gsparams: A dict of kwargs to use for a GSParams. More may be added to this
list by the galaxy object.
logger: A logger object to log progress.

Returns:
the PSF
"""
if base.get("psf", {}).get("type", "roman_psf") != "roman_psf":
return galsim.config.BuildGSObject(base, "psf", gsparams=gsparams, logger=logger)[0]

roman_psf = galsim.config.GetInputObj("roman_psf", config, base, "buildPSF")
psf = roman_psf.getPSF(self.pupil_bin, base["image_pos"])
return psf

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this beeing added back?
Same as the comment above, if there is a specific issue with the PSF it would be easier in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants